home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / src / interp / perl-5.003.tar.gz / perl-5.003.tar / perl-5.003 / t / lib / bigintpm.t < prev    next >
Text File  |  1995-01-23  |  6KB  |  311 lines

  1. #!./perl
  2.  
  3. BEGIN { unshift @INC, './lib', '../lib';
  4.     require Config; import Config;
  5. }
  6. use Math::BigInt;
  7.  
  8. $test = 0;
  9. $| = 1;
  10. print "1..246\n";
  11. while (<DATA>) {
  12.        chop;
  13.        if (s/^&//) {
  14.                $f = $_;
  15.        } else {
  16.                ++$test;
  17.                @args = split(/:/,$_,99);
  18.                $ans = pop(@args);
  19.                $try = "\$x = new Math::BigInt \"$args[0]\";";
  20.                if ($f eq "bnorm"){
  21.                    $try .= "\$x+0;";
  22.                } elsif ($f eq "bneg") {
  23.                    $try .= "-\$x;";
  24.                } elsif ($f eq "babs") {
  25.                    $try .= "abs \$x;";
  26.                } else {
  27.                    $try .= "\$y = new Math::BigInt \"$args[1]\";";
  28.                    if ($f eq bcmp){
  29.                        $try .= "\$x <=> \$y;";
  30.                    }elsif ($f eq badd){
  31.                        $try .= "\$x + \$y;";
  32.                    }elsif ($f eq bsub){
  33.                        $try .= "\$x - \$y;";
  34.                    }elsif ($f eq bmul){
  35.                        $try .= "\$x * \$y;";
  36.                    }elsif ($f eq bdiv){
  37.                        $try .= "\$x / \$y;";
  38.                    }elsif ($f eq bmod){
  39.                        $try .= "\$x % \$y;";
  40.                    }elsif ($f eq bgcd){
  41.                        $try .= "Math::BigInt::bgcd(\$x, \$y);";
  42.                    } else { warn "Unknown op"; }
  43.                }
  44.                #print ">>>",$try,"<<<\n";
  45.                $ans1 = eval $try;
  46.                if ("$ans1" eq $ans) { #bug!
  47.                        print "ok $test\n";
  48.                } else {
  49.                        print "not ok $test\n";
  50.                        print "# '$try' expected: '$ans' got: '$ans1'\n";
  51.                }
  52.        }
  53. __END__
  54. &bnorm
  55. abc:NaN
  56.    1 a:NaN
  57. 1bcd2:NaN
  58. 11111b:NaN
  59. +1z:NaN
  60. -1z:NaN
  61. 0:+0
  62. +0:+0
  63. +00:+0
  64. +0 0 0:+0
  65. 000000  0000000   00000:+0
  66. -0:+0
  67. -0000:+0
  68. +1:+1
  69. +01:+1
  70. +001:+1
  71. +00000100000:+100000
  72. 123456789:+123456789
  73. -1:-1
  74. -01:-1
  75. -001:-1
  76. -123456789:-123456789
  77. -00000100000:-100000
  78. &bneg
  79. abd:NaN
  80. +0:+0
  81. +1:-1
  82. -1:+1
  83. +123456789:-123456789
  84. -123456789:+123456789
  85. &babs
  86. abc:NaN
  87. +0:+0
  88. +1:+1
  89. -1:+1
  90. +123456789:+123456789
  91. -123456789:+123456789
  92. &bcmp
  93. abc:abc:NaN
  94. abc:+0:NaN
  95. +0:abc:NaN
  96. +0:+0:+0
  97. -1:+0:-1
  98. +0:-1:+1
  99. +1:+0:+1
  100. +0:+1:-1
  101. -1:+1:-1
  102. +1:-1:+1
  103. -1:-1:+0
  104. +1:+1:+0
  105. +123:+123:+0
  106. +123:+12:+1
  107. +12:+123:-1
  108. -123:-123:+0
  109. -123:-12:-1
  110. -12:-123:+1
  111. +123:+124:-1
  112. +124:+123:+1
  113. -123:-124:+1
  114. -124:-123:-1
  115. &badd
  116. abc:abc:NaN
  117. abc:+0:NaN
  118. +0:abc:NaN
  119. +0:+0:+0
  120. +1:+0:+1
  121. +0:+1:+1
  122. +1:+1:+2
  123. -1:+0:-1
  124. +0:-1:-1
  125. -1:-1:-2
  126. -1:+1:+0
  127. +1:-1:+0
  128. +9:+1:+10
  129. +99:+1:+100
  130. +999:+1:+1000
  131. +9999:+1:+10000
  132. +99999:+1:+100000
  133. +999999:+1:+1000000
  134. +9999999:+1:+10000000
  135. +99999999:+1:+100000000
  136. +999999999:+1:+1000000000
  137. +9999999999:+1:+10000000000
  138. +99999999999:+1:+100000000000
  139. +10:-1:+9
  140. +100:-1:+99
  141. +1000:-1:+999
  142. +10000:-1:+9999
  143. +100000:-1:+99999
  144. +1000000:-1:+999999
  145. +10000000:-1:+9999999
  146. +100000000:-1:+99999999
  147. +1000000000:-1:+999999999
  148. +10000000000:-1:+9999999999
  149. +123456789:+987654321:+1111111110
  150. -123456789:+987654321:+864197532
  151. -123456789:-987654321:-1111111110
  152. +123456789:-987654321:-864197532
  153. &bsub
  154. abc:abc:NaN
  155. abc:+0:NaN
  156. +0:abc:NaN
  157. +0:+0:+0
  158. +1:+0:+1
  159. +0:+1:-1
  160. +1:+1:+0
  161. -1:+0:-1
  162. +0:-1:+1
  163. -1:-1:+0
  164. -1:+1:-2
  165. +1:-1:+2
  166. +9:+1:+8
  167. +99:+1:+98
  168. +999:+1:+998
  169. +9999:+1:+9998
  170. +99999:+1:+99998
  171. +999999:+1:+999998
  172. +9999999:+1:+9999998
  173. +99999999:+1:+99999998
  174. +999999999:+1:+999999998
  175. +9999999999:+1:+9999999998
  176. +99999999999:+1:+99999999998
  177. +10:-1:+11
  178. +100:-1:+101
  179. +1000:-1:+1001
  180. +10000:-1:+10001
  181. +100000:-1:+100001
  182. +1000000:-1:+1000001
  183. +10000000:-1:+10000001
  184. +100000000:-1:+100000001
  185. +1000000000:-1:+1000000001
  186. +10000000000:-1:+10000000001
  187. +123456789:+987654321:-864197532
  188. -123456789:+987654321:-1111111110
  189. -123456789:-987654321:+864197532
  190. +123456789:-987654321:+1111111110
  191. &bmul
  192. abc:abc:NaN
  193. abc:+0:NaN
  194. +0:abc:NaN
  195. +0:+0:+0
  196. +0:+1:+0
  197. +1:+0:+0
  198. +0:-1:+0
  199. -1:+0:+0
  200. +123456789123456789:+0:+0
  201. +0:+123456789123456789:+0
  202. -1:-1:+1
  203. -1:+1:-1
  204. +1:-1:-1
  205. +1:+1:+1
  206. +2:+3:+6
  207. -2:+3:-6
  208. +2:-3:-6
  209. -2:-3:+6
  210. +111:+111:+12321
  211. +10101:+10101:+102030201
  212. +1001001:+1001001:+1002003002001
  213. +100010001:+100010001:+10002000300020001
  214. +10000100001:+10000100001:+100002000030000200001
  215. +11111111111:+9:+99999999999
  216. +22222222222:+9:+199999999998
  217. +33333333333:+9:+299999999997
  218. +44444444444:+9:+399999999996
  219. +55555555555:+9:+499999999995
  220. +66666666666:+9:+599999999994
  221. +77777777777:+9:+699999999993
  222. +88888888888:+9:+799999999992
  223. +99999999999:+9:+899999999991
  224. &bdiv
  225. abc:abc:NaN
  226. abc:+1:abc:NaN
  227. +1:abc:NaN
  228. +0:+0:NaN
  229. +0:+1:+0
  230. +1:+0:NaN
  231. +0:-1:+0
  232. -1:+0:NaN
  233. +1:+1:+1
  234. -1:-1:+1
  235. +1:-1:-1
  236. -1:+1:-1
  237. +1:+2:+0
  238. +2:+1:+2
  239. +1000000000:+9:+111111111
  240. +2000000000:+9:+222222222
  241. +3000000000:+9:+333333333
  242. +4000000000:+9:+444444444
  243. +5000000000:+9:+555555555
  244. +6000000000:+9:+666666666
  245. +7000000000:+9:+777777777
  246. +8000000000:+9:+888888888
  247. +9000000000:+9:+1000000000
  248. +35500000:+113:+314159
  249. +71000000:+226:+314159
  250. +106500000:+339:+314159
  251. +1000000000:+3:+333333333
  252. +10:+5:+2
  253. +100:+4:+25
  254. +1000:+8:+125
  255. +10000:+16:+625
  256. +999999999999:+9:+111111111111
  257. +999999999999:+99:+10101010101
  258. +999999999999:+999:+1001001001
  259. +999999999999:+9999:+100010001
  260. +999999999999999:+99999:+10000100001
  261. &bmod
  262. abc:abc:NaN
  263. abc:+1:abc:NaN
  264. +1:abc:NaN
  265. +0:+0:NaN
  266. +0:+1:+0
  267. +1:+0:NaN
  268. +0:-1:+0
  269. -1:+0:NaN
  270. +1:+1:+0
  271. -1:-1:+0
  272. +1:-1:+0
  273. -1:+1:+0
  274. +1:+2:+1
  275. +2:+1:+0
  276. +1000000000:+9:+1
  277. +2000000000:+9:+2
  278. +3000000000:+9:+3
  279. +4000000000:+9:+4
  280. +5000000000:+9:+5
  281. +6000000000:+9:+6
  282. +7000000000:+9:+7
  283. +8000000000:+9:+8
  284. +9000000000:+9:+0
  285. +35500000:+113:+33
  286. +71000000:+226:+66
  287. +106500000:+339:+99
  288. +1000000000:+3:+1
  289. +10:+5:+0
  290. +100:+4:+0
  291. +1000:+8:+0
  292. +10000:+16:+0
  293. +999999999999:+9:+0
  294. +999999999999:+99:+0
  295. +999999999999:+999:+0
  296. +999999999999:+9999:+0
  297. +999999999999999:+99999:+0
  298. &bgcd
  299. abc:abc:NaN
  300. abc:+0:NaN
  301. +0:abc:NaN
  302. +0:+0:+0
  303. +0:+1:+1
  304. +1:+0:+1
  305. +1:+1:+1
  306. +2:+3:+1
  307. +3:+2:+1
  308. +100:+625:+25
  309. +4096:+81:+1
  310.